using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The RelationshipTypeCodeTableManager class is responsible for managing BO.RelationshipTypeCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class RelationshipTypeCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all RelationshipTypeCodeTable objects in the database.
/// </summary>
/// <returns>A list with all RelationshipTypeCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static RelationshipTypeCodeTableList GetList(){
return RelationshipTypeCodeTableDB.GetList();
}

/// <summary>
/// Gets a single RelationshipTypeCodeTable from the database without its data.
/// </summary>
/// <param name="relationshipTypeCode">The RelationshipTypeCode of the RelationshipTypeCodeTable in the database.</param>
/// <returns>A RelationshipTypeCodeTable object when the RelationshipTypeCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static RelationshipTypeCodeTable GetItem(short relationshipTypeCode){
return GetItem(relationshipTypeCode, false);
}

/// <summary>
/// Gets a single RelationshipTypeCodeTable from the database.
/// </summary>
/// <param name="relationshipTypeCode">The RelationshipTypeCode of the RelationshipTypeCodeTable in the database.</param>
/// <param name="getRelationshipTypeCodeTableRecords">Determines whether to load all associated RelationshipTypeCodeTable records as well.</param>
/// <returns>
/// A RelationshipTypeCodeTable object when the RelationshipTypeCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static RelationshipTypeCodeTable GetItem(short relationshipTypeCode, bool getRelationshipTypeCodeTableRecords){
RelationshipTypeCodeTable myRelationshipTypeCodeTable = RelationshipTypeCodeTableDB.GetItem(relationshipTypeCode);
if (myRelationshipTypeCodeTable != null && getRelationshipTypeCodeTableRecords){
myRelationshipTypeCodeTable.studentFamilyMemberRelationshipTables = StudentFamilyMemberRelationshipTableDB.GetListByRelationshipTypeCode(relationshipTypeCode);
}
if (myRelationshipTypeCodeTable != null && getRelationshipTypeCodeTableRecords){
myRelationshipTypeCodeTable.studentGuardianRelationshipTables = StudentGuardianRelationshipTableDB.GetListByRelationshipTypeCode(relationshipTypeCode);
}
return myRelationshipTypeCodeTable;
}

/// <summary>
/// Saves a RelationshipTypeCodeTable in the database.
/// </summary>
/// <param name="myRelationshipTypeCodeTable">The RelationshipTypeCodeTable instance to save.</param>
/// <returns>The new RelationshipTypeCode if the RelationshipTypeCodeTable is new in the database or the existing RelationshipTypeCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(RelationshipTypeCodeTable myRelationshipTypeCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short relationshipTypeCodeTableRelationshipTypeCode = RelationshipTypeCodeTableDB.Save(myRelationshipTypeCodeTable);
foreach (StudentFamilyMemberRelationshipTable myStudentFamilyMemberRelationshipTable in myRelationshipTypeCodeTable.studentFamilyMemberRelationshipTables){
myStudentFamilyMemberRelationshipTable.RelationshipTypeCode = relationshipTypeCodeTableRelationshipTypeCode;
StudentFamilyMemberRelationshipTableDB.Save(myStudentFamilyMemberRelationshipTable);
}
foreach (StudentGuardianRelationshipTable myStudentGuardianRelationshipTable in myRelationshipTypeCodeTable.studentGuardianRelationshipTables){
myStudentGuardianRelationshipTable.RelationshipTypeCode = relationshipTypeCodeTableRelationshipTypeCode;
StudentGuardianRelationshipTableDB.Save(myStudentGuardianRelationshipTable);
}

//  Assign the RelationshipTypeCodeTable its new (or existing RelationshipTypeCode).
myRelationshipTypeCodeTable.RelationshipTypeCode = relationshipTypeCodeTableRelationshipTypeCode;

myTransactionScope.Complete();

return relationshipTypeCodeTableRelationshipTypeCode;
}
}

/// <summary>
/// Deletes a RelationshipTypeCodeTable from the database.
/// </summary>
/// <param name="myRelationshipTypeCodeTable">The RelationshipTypeCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(RelationshipTypeCodeTable myRelationshipTypeCodeTable){
return RelationshipTypeCodeTableDB.Delete(myRelationshipTypeCodeTable.RelationshipTypeCode);
}

#endregion

}

}
